#!/usr/bin/env bash
# 下载 ARM64 Linux 平台的完整依赖包

set -euo pipefail

PLATFORM="manylinux2014_aarch64"
PYTHON_VERSION="312"
DEST_DIR="./packages_arm64_complete"

echo "创建目标目录..."
mkdir -p "$DEST_DIR"

echo "下载主要依赖及其传递依赖..."

# 下载主要依赖和所有传递依赖
pip download -r requirements.txt \
    --platform "$PLATFORM" \
    --python-version "$PYTHON_VERSION" \
    --implementation cp \
    --only-binary=:all: \
    --dest "$DEST_DIR"

# 单独下载 greenlet（SQLAlchemy 的依赖）
echo "下载 greenlet..."
pip download greenlet \
    --platform "$PLATFORM" \
    --python-version "$PYTHON_VERSION" \
    --implementation cp \
    --only-binary=:all: \
    --dest "$DEST_DIR"

# 下载其他可能缺失的依赖
echo "下载其他依赖..."
pip download \
    setuptools wheel pip \
    --platform "$PLATFORM" \
    --python-version "$PYTHON_VERSION" \
    --implementation cp \
    --only-binary=:all: \
    --dest "$DEST_DIR" || true

echo "依赖下载完成，位于: $DEST_DIR"
echo "文件列表:"
ls -la "$DEST_DIR"

echo ""
echo "在目标 Linux ARM64 机器上安装："
echo "1. 传输整个 $DEST_DIR 目录到目标机器"
echo "2. 运行: pip3.12 install --no-index --find-links=$DEST_DIR --force-reinstall *"
